package scribes.mybus.client;

import javax.naming.Context;
import javax.naming.NamingException;

import scribes.mybus.client.Client;

import scribes.mybus.ejb.MyBusProjectBean;

public class Client {

	/**
	 * 
	 * For client to upload and retreive data in the JSONOutput and KMLOutput format
	 * 
	 */
	private static final String LOOKUP_STRING = "MyBusProjectEJBBean/remote";
	    public static void main(String[] args) {
	          MyBusProjectBean bean = doLookup();
		       String filepath="C:\\Users\\ws\\23.txt";
		       //System.out.println(filepath);
		        Client busClient = new Client();

		         bean.uploadFile(filepath);
				String outputString = busClient.getBusInfo(23,"jsonOuputFormat"); //jsonOuputFormat kmlOutputFormat
				System.out.println(outputString);
				
				
		       
	    }
	    
	  
	 
	    public String getBusInfo(int busId, String desiredOutputFormat) {
			String outputStr = "";
			if (busId <0)
				throw new RuntimeException("Bus Id not found");
			try {
				MyBusProjectBean bean = doLookup();
				outputStr = bean.getCurrentBusInfo(busId, desiredOutputFormat);
			} catch (Exception e) {

				e.printStackTrace();
			}
			return outputStr;
		}
	 
	    private static MyBusProjectBean doLookup(){
	        Context context = null;
	        MyBusProjectBean bean = null;
	        try{
	                    //1. Obtaining Context
	            context = ClientUtility.getInitialContext();
	                //2. Lookup and cast
	                bean = (MyBusProjectBean)context.lookup(LOOKUP_STRING);
	        }catch(NamingException e){
	            e.printStackTrace();
	        }
	        return bean;
	    }

	

}
